package com.example.webapi.json;

import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.setting.Setting;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

public class test2 {
    public static void main(String[] args) {
        Map<String, Object> paramMap = new HashMap<>();
        Setting setting = new Setting("config/project.setting");
        //获取token
        String loginPath = setting.getStr("loginPath");
        paramMap.put("username","admin");
        paramMap.put("password","123456");
        String loginResult = HttpUtil.post(loginPath, paramMap);
        JSONObject jsonObject = JSONUtil.parseObj(loginResult);
        Object userInfo = jsonObject.get("data");
        JSONObject mapUserInfo= JSONUtil.parseObj(userInfo);
        System.out.println(mapUserInfo);
        // 获取项目列表
        String projectListUrl = setting.getStr("getProjectList");
        paramMap.clear();
        paramMap.put("ywlxId","1217735877707505665");
        paramMap.put("page","1");
        paramMap.put("limit","-1");
        System.err.println("2: " + LocalDateTime.now());
        String projectList = HttpRequest.get(projectListUrl).header("token", Convert.toStr(mapUserInfo.get("sid")))
                .form(paramMap).execute().body();
        System.err.println("3: " + LocalDateTime.now());
        JSONObject jsonProjectList = JSONUtil.parseObj(projectList);
        JSONArray jsonObject1 = JSONUtil.parseArray(jsonProjectList.get("data"));
        //获取文件相对路径
        paramMap.clear();
        String getFileInfoUrl = setting.getStr("getFileInfo");
        paramMap.put("processInstId","bec94de8-d034-4ed7-87a8-27c5b784b49b");
//        paramMap.put("taskInstId","574176a3-0314-43b7-9297-4b0405638a2b");
//        paramMap.put("activityDefId","obj_c8f1fed8957000016e8f6fb068725590");
        String fileInfoList = HttpRequest.get(getFileInfoUrl).header("token", Convert.toStr(mapUserInfo.get("sid")))
                .form(paramMap).execute().body();
        JSONObject jsonFileInfoList = JSONUtil.parseObj(fileInfoList);
        JSONArray arrayFileInfoList = JSONUtil.parseArray(jsonFileInfoList.get("data"));
        for (Object map:arrayFileInfoList){
            JSONObject fileInfo = JSONUtil.parseObj(map);
            System.out.println(fileInfo);
            if (Convert.toStr(fileInfo.get("name")).contains(".ifc+")){
                System.out.println(fileInfo.get("name"));
            }
        System.out.println(jsonObject1);

    }
    }

}
